import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:程序逻辑控制相关知识
 * User: 阿宾
 * Date: 2024-05-02
 * Time: 16:10
 */
public class Test01 {
    public static void main(String[] args) {
        //计算1/1-1/2+1/3-1/4+1/5 …… + 1/99 - 1/100 的值

        double sum = 0.0;
        int flag = 1;
        for (int i = 1; i <= 100 ; i++) {
//            sum += Math.pow(flag,i-1)/i;
            sum += flag * 1.0 /i;
            flag = -flag;
        }
        System.out.println(sum); //0.688172179310195
    }
    public static void main19(String[] args) {
        //获取一个数二进制序列中所有的偶数位和奇数位，分别输出二进制序列。
        Scanner scan = new Scanner(System.in);
        int num = scan.nextInt();
        //输入的是一个int类型的数值
        //偶数位：
        for (int i = 31; i >= 1; i-=2) {
            System.out.print(((num >> i) & 1) + " ");
        }

        System.out.println();
          //奇数位：
        for (int i = 30; i >=0 ; i-=2) {
            System.out.print(((num >> i) & 1) + " ");
        }
    }
    public static void main18(String[] args) {
        int count = 0;
        //产生1~100数字
        //9 19 29 39 49 59 69 79 89  90 91 92 93 94 95 96 97 98 99
        for (int i = 0; i < 101; i++) {
            if(i % 10 == 9 || i / 10 % 10 == 9){
                count++;
            }
        }
        System.out.println(count + 1);
        /*int count = 0;
        for (int i = 1; i <= 100; i++) {
            if(i % 10 == 9) {//判断个位的9
                count++;
            }
            if(i/10 == 9) {
                count++;//判断十位的9
            }
        }
        System.out.println(count);*/
    }
    public static void main17(String[] args) {
        //判断一个数字是否是素数:除了1和它本身外没有其他数可以整除
        Scanner scan  = new Scanner(System.in);
        int num = scan.nextInt();
        boolean flag = true;//默认表示输入的是质数
        int count = 0;
        //求开根号的方式 Math.sqrt()
        int i = 0;
        for (i = 2; i <= Math.sqrt(num); i++) {
            count++;
            if(num % 2 == 0) {
                flag = false;
                break;
            }
        }
        if(flag && num > 1){//1不是质数也不是合数
            System.out.println(num + "是素数");
        }else{
            System.out.println(num + "不是素数");
        }
        System.out.println(count);
    }
    public static void main16(String[] args) {
        //输入一个数据
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入一个整数：");
        int number = scanner.nextInt();
        int count = 0;
        boolean flag = true;//默认表示该整数是质数
        //判断
        for(int i = 2;i < number;i++){
            count++;
            if(number % i == 0){
                //说明不是质数

                flag = false;
                break;//不用执行后续代码，直接跳出循环
            }
        }
        //需要单独判断1
        if(flag && number > 1){
            System.out.println(number + "是一个质数");
        }else{
            System.out.println(number + "不是一个质数");
        }
        System.out.println(count);
    }
    public static void main15(String[] args) {
        int x = 121;
        int copy = x;
        int num = 0;
        while(x != 0){
            num =  num * 10 + x % 10;
            x /= 10;
        }
        if(copy == num){
            System.out.println(num + "是回文数");
        }else {
            System.out.println(num + "不是回文数");
        }

    }
    public static void main14(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.println("请输入第一个数字：");
        int num1 = scanner.nextInt();
        System.out.println("请输入第二个数字：");
        int num2 = scanner.nextInt();

        int ret = 0;
        for(int i = num1;i <= num2;i++){
            if(i % 3 == 0 && i % 5 == 0){
                System.out.print(i + " ");
                ret++;
            }
        }
        System.out.println();
        System.out.println("总共符合条件的数字有：" + ret);
    }
    public static void main13(String[] args) {
        int key = 1;//表示加到几的阶乘
        int sum = 0;//表示最后的阶乘之和
        while(key <= 5){
            int num = 1;
            int ret = 1;
            while(num <= key){
                ret *= num;
                num++;
            }
            key++;
            sum += ret;
        }
        System.out.println(sum);
    }
    public static void main12(String[] args) {
        int x = 10;
        int y = 10;
        if (x > 10)
            if (y == 10)
                System.out.println("aaa");
        else
            System.out.println("bbb");
    }
    public static void main11(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入一个数字：");
        int num = scanner.nextInt();
        if(num > 0){
            System.out.println(num + "是一个正数");
        }else if(num < 0){
            System.out.println(num + "是一个负数");
        }else {
            System.out.println(num + "是零");
        }
    }
    public static void main10(String[] args) {
        System.out.println("开始");
        //定义两个变量
        int a = 10;
        int b = 20;
        //需求：判断a是否大于b，如果是，在控制台输出：a的值大于b，否则，在控制台输出：a的值不大于b
        if(a > b) {
            System.out.println("a的值大于b");
        } else {
            System.out.println("a的值不大于b");
        }
        System.out.println("结束");
    }
    public static void main9(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入年份：");
        int year = scanner.nextInt();
        if((year % 4 == 0 && year % 400 != 0) || year % 400 == 0){
            System.out.println(year + "是闰年");//字符串的拼接
        }
    }
    public static void main1(String[] args) {
        int score = 80;
        if(score >= 20)
        {
            System.out.println("very good");
        }else
        {
            System.out.println("No");
        }
    }

    public static void main2(String[] args) {
        //判断一个数是奇数还是偶数
        int num = 5;
        if(num % 2 == 0)
        {
            System.out.println("是偶数");
        } else {
            System.out.println("是奇数");
        }
    }

    public static void main3(String[] args) {
        //判断是否是闰年
        //1、能被4整除且不能被100整除
        //2、能被400整除
//        int year = 2024;
//        if(year % 4 == 0 && year % 100 != 0)
//        {
//            System.out.println("是闰年");
//        }else if(year % 400 == 0)
//        {
//            System.out.println("是闰年");
//        }else
//        {
//            System.out.println("不是闰年");
//        }
        /*if((year % 4 == 0 && year % 100 != 0) ||(year % 400 == 0)) {
            System.out.println(year + "是闰年");
        }*/
        /*
        switch语句
        不能做switch数据类型有哪些？
        1、floot
        2、double
        3、long
         */
        /*String a = "hello";
        switch(a){
            case "1":
                System.out.println(a);
                break;
            case "2":
                System.out.println(a);
                break;
            case "3":
                System.out.println(a);
                break;
            default:
                System.out.println(a);
                break;
        }*/

  /*      boolean b1 = true;
        switch(b1) {
            case 1:
                break;
        }*/


    }

    public static void main4(String[] args) {
        /*
        循环语句
         */
/*        //打印1~10数字
        int num = 1;
        while(num <= 10){
            System.out.print(num+" ");//print表示不换行，println表示换行
            num ++;
        }*/
/*        //求1~100的和
        int sum = 0;
        int num = 1;
        while(num <= 100){
            sum += num;
            num++;
        }
        System.out.println(sum);*/

        //求5!
/*        int num = 1;
        int ret = 1;
        while(num <= 5){
            ret *= num;
            num++;
        }
        System.out.println(ret);*/

        //求1！+2！+3！+4！+5！+6！
        int key = 1;//表示加到几的阶乘
        int sum = 0;//表示最后的阶乘之和
        while(key <= 6){
            int num = 1;
            int ret = 1;
            while(num <= key){
                ret *= num;
                num++;
            }
            key++;
            sum += ret;
        }
        System.out.println(sum);
    }

    public static void main5(String[] args) {
 /*       int num = 100;
        while(num <= 300){
            if(num % 3 == 0){
                System.out.println("100~300的第一个3的倍数是："+ num);
                break;
            }
            num++;
        }*/
        //求出100~200既能被3整除，也能被4整除的数字
        //方法1：
        /*int num = 100;
        while(num <= 300){
            if(num % 3 == 0 && num % 4 == 0){
                System.out.print(num+" ");
            }
            num++;
        }*/
        //方法2：
        int num = 100;
        while(num <= 200){
            if(num % 3 != 0 || num % 4 != 0){
                num++;
                continue;
            }
            System.out.print(num+" ");
            num++;
        }
    }

    public static void main6(String[] args) {
        /*
        //求5!
        int sum = 1;
        for (int i = 1; i <= 5; i++) {
            sum *= i;
        }
        System.out.println(sum);*/
        //求1！+2！+3!+4!+5!
        int ret = 0;
        for (int i = 1; i <= 5; i++) {
            int sum = 1;
            for (int j = 1; j <= i; j++) {
                sum *= j;
            }
            ret += sum;
        }
        System.out.println(ret);
    }

    public static void main7(String[] args) {
        /*
        输入需要导入包 import java.util.Scanner;
        Scanner
         */
        Scanner scan = new Scanner(System.in);

        System.out.println("输入一个整数：");
        int age = scan.nextInt();//读入一个int类型的整数
        System.out.println("年龄："+age);

        scan.nextLine();//读取回车

        System.out.println("请输入你的姓名：");
        String name = scan.nextLine();//nextLine读入一行，next是遇到空格结束
        //String name = scan.next();//遇到空格就结束
        System.out.println("姓名："+name);




        System.out.println("请输入您的工资：");
        float salary = scan.nextFloat();//读入一个float类型的数据
        System.out.println("工资"+salary);

        scan.close();//认为scan是一个资源


    }

    public static void main8(String[] args) {
        Scanner scan = new Scanner(System.in);

        /*while(scan.hasNextInt()){//是否有下一个整数

            int age = scan.nextInt();
            System.out.println(age);
        }*/
        while(scan.hasNextFloat()){
            float age = scan.nextFloat();
            System.out.println(age);

        }
        //将多组输入停下来，在IDEA中使用ctrl+d
    }
}
